home *** CD-ROM | disk | FTP | other *** search
/ Packard Bell - Internet on a CD / internet on a cd.cdr / Internet / sites / HTML_1 / hangman-nice-1.pl < prev    next >
Encoding:
Perl Script  |  1998-07-16  |  3.3 KB  |  101 lines

  1. #!/bin/perl
  2.  
  3. require "cgi-lib.pl";
  4.  
  5. if (&ReadParse(*input)) {
  6.      print &PrintHeader;
  7.      print "<title> Hangman </title>";
  8.      print "<h1>The Hangman Game ...</h1>";
  9.      if ($input{'done'} eq 'done') # the person guessed the word
  10.     { if ($input{'real'} eq $input{'new'}) # did they get it right?
  11.             {print 'You were right.';}
  12.           else {print 'You were WRONG!<p>';
  13.                 print 'It was really ',$input{'real'},'.';}
  14.           print '<p><p>Click <a href="/cgi-bin/nik/hangman-nice.pl">';
  15.           print 'here</a> to play again.';
  16.           return;
  17.        }
  18.      $input{'new'} =~ s/^(.)(.*)/$1/;  # only get the 1st char
  19.      $guess = $input{'new'}.' '.$input{'guess'}; # put the new one in $guess
  20.      @sofar = split(/\s+/,$guess); # make guess into an array
  21.      $gue = @sofar;
  22.      $num = length($input{'real'});
  23.      @rreal = split(/ */,$input{'real'}); # make the real word into an array
  24.                       # buy splitting on space or nil
  25.      print '<p>';
  26.      print 'So far you have guessed:<p>';
  27.      $gotten = 0;
  28.      LET: for ($i=0;$i<$num;$i++)  #go through the real word
  29.        { $temp = $rreal[$i];
  30.          for ($g=0;$g<$gue;$g++) #go through the guesses
  31.         { if ($sofar[$g] eq $temp) 
  32.              { print $temp;
  33.                $gotten = $gotten +1;
  34.                next LET;
  35.                }
  36.         }
  37.              print '_ ';
  38.          }
  39.      print '<p>';
  40.      print '<img src="http://blackcat.brynmawr.edu/~nswoboda/scripts/hang',($gue-$gotten),'.gif"><p>';
  41.      if (($gue-$gotten) < 6) {
  42.         print 'Please type your next guess<p>';
  43.     print 'You have ',(6-($gue-$gotten)),' guesse(s) left!<p>';
  44.  
  45.     print <<EOF
  46. <form method="post" action="/cgi-bin/nik/hangman-nice.pl">
  47. <input name = "new"><p>
  48. <input type="hidden" name="guess" value="$guess">
  49. <input type="hidden" name="real" value="$input{'real'}">
  50. <INPUT TYPE="reset" VALUE="Clear">
  51. <input type="submit" value="Continue">
  52. </form>
  53. Or if you are daring type in what you think that the word is.<p> 
  54. <form method="post" action="/cgi-bin/nik/hangman-nice.pl">
  55. <input name="new"><p> 
  56. <input type="hidden" name="done" value="done"> 
  57. <input type="hidden" name="real" value="$input{'real'}">
  58. <INPUT TYPE="reset" VALUE="Clear"> 
  59. <input type="submit" value="Guess It">
  60. </form> </html>
  61. EOF
  62.         }
  63.      else{
  64.     print <<EOF
  65. Sorry the game is over.<p>
  66. The correct answer is $input{'real'}.<p>
  67. click <a href="/cgi-bin/nik/hangman.pl"> here</a> to play again.
  68. EOF
  69.         }
  70.      }
  71. else {
  72.     print &PrintHeader;
  73.     print '<title> Hangman </title>';
  74.     print '<h1> Hangman Game.</h1><br>';
  75.     $real = "first";
  76.     $num = length($real);
  77.     for ($i=1;$i<=$num;$i++)
  78.      { print '_ ';
  79.       }
  80.     print '<p>';
  81.     print '<img src="http://blackcat.brynmawr.edu/~nswoboda/scripts/hang0.gif"><p>';
  82.     print 'Type in your first guess at the above unknown word.<p>';
  83.     print <<EOF
  84. <form method="post" action="/cgi-bin/nik/hangman-nice.pl">
  85. <input name = "new"><p>
  86. <input type="hidden" name="guess" value="">
  87. <input type="hidden" name="real" value="$real">
  88. <INPUT TYPE="reset" VALUE="Clear">
  89. <input type="submit" value="Continue">
  90. </form>
  91. Or if you are daring type in what you think that the word is.<p>
  92. <form method="post" action="/cgi-bin/nik/hangman-nice.pl">
  93. <input name="new"><p>
  94. <input type="hidden" name="done" value="done">
  95. <input type="hidden" name="real" value="$real">
  96. <INPUT TYPE="reset" VALUE="Clear">
  97. <input type="submit" value="Guess It">
  98. </form> </html>
  99. EOF
  100.     }
  101.